// pages/home/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageData: [{
      name: '服务评价',
      src: '../../images/bt_jkzx.png'
    },{
      name:'健康咨询',
      src:'../../images/bt_jkzx.png'
    },{
        name: '药品评价',
        src: '../../images/bt_yppj.png'
    },{
        name: '奖励提现',
        src: '../../images/bt_jltx.png'
    }],
    hasPhoneNum:false,
    hasMainStoreId:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    if (options.mainStoreId && options.mainStoreId != ''){
      this.setData({
        hasMainStoreId:true
      })
      app.mainStoreId = options.mainStoreId
    }else{
      this.getSysteminfo()

      // wx.showModal({
      //   title: '提示',
      //   content: '请点击公众号菜单或模板消息进入',
      //   showCancel:false
      // })
    }
    wx.login({

    })
    wx.getStorage({
      key: 'userinfo',
      success: function (res) {
        console.log(res)
        app.hasPhoneNum = true
        app.userId = res.data.userId
        app.openid = res.data.openid
        that.setData({
          hasPhoneNum: true
        })
      },
      fail: function (res) {
        console.log(res)
       
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  clickAction(e){
    console.log(2)
    if (!app.isConfigDrug && e.currentTarget.id == '1'){
      wx.showModal({
        title: '提示',
        content: '暂未开放，敬请期待',
        showCancel: false
      })
      return
    }
    if (!app.isConfigQuestion && e.currentTarget.id == '0') {
      wx.showModal({
        title: '提示',
        content: '暂未开放，敬请期待',
        showCancel: false
      })
      return
    }
    if(!this.data.hasMainStoreId){
      wx.showModal({
        title: '提示',
        content: '请点击公众号菜单或模板消息进入',
        showCancel: false
      })
      return
    }


    if (!this.data.hasPhoneNum){
      return
    }
    if (e.currentTarget.id == '0') { // 服务评价
      wx.navigateTo({
        url: '/pages/evaluatePaging/index',
      })
    } else if(e.currentTarget.id == '1'){ // 健康咨询
      wx.navigateTo({
        url: '/pages/consultationHome/index',
      })
    } else if (e.currentTarget.id == '2'){ // 药品评价
      wx.navigateTo({
        url: '/pages/healthcoinDetail/index?id=' + true,
      })
    }else{ // 奖励提现
      wx.navigateTo({
        url: '/pages/myCoin/index',
      })
    }
  },
  getPhoneNumber(e){
    // console.log(e)
    var that = this
    app.getPhoneNum(e,result=>{
      console.log(result)
      that.setData({
        hasPhoneNum: app.hasPhoneNum
      })
      that.clickAction(e)
    })
  },



  getSysteminfo(){
    var that = this
    // app.post(app.Apis.GET_CONFIGS, {
    //   groupId: 'XCX_MEMBER',
    //   belongToId: 'xcx_carelinker_consult'
    // }, result => {
    //   console.log(result)
    //   if (result.success) {
    //     for (var i = 0; i < result.dataList.length;i++){
    //       if (result.dataList[i].key == "XCX_CONSULT_AUDITING"){
    //         if (result.dataList[i].value==app.ver){
    //           that.setData({
    //             hasMainStoreId:true
    //           })
    //           app.mainStoreId = '9990000'
    //         }else{
    //           wx.showModal({
    //             title: '提示',
    //             content: '请点击公众号菜单或模板消息进入',
    //             showCancel: false
    //           })
    //         }
    //         return
    //       }
    //     }
    //   }
    // })
   

      app.getSysConfig('XCX_MEMBER', result1 => {

        for (var i = 0; i < result1.dataList.length; i++) {
          if (result1.dataList[i].key == "XCX_CONSULT_AUDITING") {
            if (result1.dataList[i].value == app.ver) {
              that.setData({
                hasMainStoreId: true
              })
              app.mainStoreId = '9990000'
              app.belongToId = '9990000'
            } else {
              wx.showModal({
                title: '提示',
                content: '请点击公众号菜单或模板消息进入',
                showCancel: false
              })
            }


            app.getSysConfig('XCX_CONSULT', result => {
              console.log(result)
              let configs = {}
              result.dataList.forEach(item => {
                configs[item.key] = item.value
              })
              let isConfigQuestion = configs["OPEN_XCX_CONSULT_QUESTION"]
              let isConfigDrug = configs["OPEN_XCX_CONSULT_DRUG"]
              app.isConfigQuestion = isConfigQuestion == 'true'
              app.isConfigDrug = isConfigDrug == 'true'
              console.log(app.isConfigQuestion, app.isConfigDrug)

            })




            return
          }
        }



      })



  }
})